package com.wuyou.securitydemo.component;

import com.wuyou.sso.common.bean.ResultBean;
import com.wuyou.securitydemo.domain.AuthDTO;
import com.wuyou.securitydemo.service.AuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * CustomizedAuthEndpoint
 *
 * @Date 2025/3/27 17:50
 * @Author 无忧
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/token")
public class CustomizedAuthEndpoint {

    @Autowired
    private AuthService authService;

    @PostMapping(value = "/login")
    public ResultBean auth(@RequestBody @Validated AuthDTO authDTO){
        return ResultBean.ok(authService.auth(authDTO));
    }

    @GetMapping("/logout")
    public ResultBean logout(
            @RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authHeader) {

        authService.logout(authHeader);
        return ResultBean.ok();
    }
}
